package consultan.vanke.com.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import consultan.vanke.com.R;
import consultan.vanke.com.adapter.CommonAdapter;
import consultan.vanke.com.adapter.ViewHolder;
import consultan.vanke.com.bean.HomeJumpBean;
import consultan.vanke.com.constant.ConstantLibrary;
import consultan.vanke.com.event.MessageEvent;
import consultan.vanke.com.utils.SimpleToolbar;

import static com.bytedance.sdk.account.open.aweme.utils.ViewUtils.getStatusBarHeight;
import static consultan.vanke.com.utils.StatusBarUtil.setRootView;


public class MsDetailFragment extends BaseFragment {
    @BindView(R.id.linear_left)
    LinearLayout linearLeft;
    @BindView(R.id.linear_content)
    LinearLayout linearContent;
    @BindView(R.id.linear_pingjia)
    LinearLayout linearPingjia;
    @BindView(R.id.tv_qianggou)
    TextView tvQianggou;
    @BindView(R.id.recy_list)
    RecyclerView recyList;
    @BindView(R.id.recy_list1)
    RecyclerView recyList1;
    private View inflate;
    private boolean isfristshow = true;
    @BindView(R.id.simple_toolbar)
    SimpleToolbar simpleToolbar;
    @BindView(R.id.simple_toolbar_main)
    ConstraintLayout simpleToolbarMain;
    private CommonAdapter<String> adapterCenter, adapterCenter1;
    private List<String> subjectsBeansCenter = new ArrayList<>();

    @Override
    protected void initViews() {
        simpleToolbar.setMainBg(getResources().getColor(R.color.color_f5f5f5));
        simpleToolbar.setMainTitle("");
    }

    @Override
    protected void initDatas() {
        for (int i = 0; i < 4; i++) {
            View basemessage2 = View.inflate(_mActivity, R.layout.taocan_item_child, null);
            View basemessage3 = View.inflate(_mActivity, R.layout.pingjia_item_child, null);
            linearContent.addView(basemessage2);
            linearPingjia.addView(basemessage3);
        }
        for (int i = 0; i < 10; i++) {
            subjectsBeansCenter.add("111");
        }
        LinearLayoutManager layoutManager = new LinearLayoutManager(_mActivity);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        LinearLayoutManager layoutManager1 = new LinearLayoutManager(_mActivity);
        layoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyList.setLayoutManager(layoutManager);
        recyList1.setLayoutManager(layoutManager1);
        adapterCenter = new CommonAdapter<String>(_mActivity, subjectsBeansCenter, R.layout.photo_item_child1) {
            @Override
            public void onBindViewHolder(ViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
            }

            @Override
            public void convert(ViewHolder holder, String assetBean) {
            }

        };
        adapterCenter1 = new CommonAdapter<String>(_mActivity, subjectsBeansCenter, R.layout.photo_item_child) {
            @Override
            public void onBindViewHolder(ViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
            }

            @Override
            public void convert(ViewHolder holder, String assetBean) {
            }

        };
        recyList.setAdapter(adapterCenter);
        recyList1.setAdapter(adapterCenter1);
    }

    @Override
    protected void initEvents() {
        simpleToolbar.setLeftTitleClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop();
            }
        });
    }

    @Override
    protected View initContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        inflate = View.inflate(_mActivity, R.layout.ms_detail_fragment, null);
        return inflate;
    }

    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
        ViewGroup decorView = (ViewGroup) _mActivity.getWindow().getDecorView();
        View fakeStatusBarView = new View(_mActivity);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(_mActivity) + 3);
        fakeStatusBarView.setLayoutParams(params);
        fakeStatusBarView.setBackground(getResources().getDrawable(R.drawable.bg_gray_bg));
        fakeStatusBarView.setId(android.R.id.custom);
        decorView.addView(fakeStatusBarView);
        setRootView(_mActivity, false);
//        if (isfristshow) {
//            setPaddingTop(_mActivity, simpleToolbar);
//            isfristshow = false;
//        }
        setStatusBarColors(getResources().getColor(R.color.color_f5f5f5), true);
    }

    @OnClick(R.id.tv_qianggou)
    public void onViewClicked() {
        MessageEvent<HomeJumpBean> messageEvent = new MessageEvent<>();
        messageEvent.setData(new HomeJumpBean(ConstantLibrary.djqFragment, ConstantLibrary.TYPE_TIME_OUT));
        EventBus.getDefault().post(messageEvent);
    }
}
